"""
一帮一
"""
n = eval(input())
list1 = []
for i in range(n):
    gender, name = input().split()
    list1.append([int(gender), name])
len1 = len(list1) // 2
for i in range(len1):
    j = 1
    while True:
        if list1[i][0] != list1[len(list1)-j][0]:
            print(f'{list1[i][1]} {list1[len(list1)-j][1]}')
            list1.pop(len(list1)-j)
            break
        else:
            j += 1
